package com.xlf.common.auth.dao;

import com.xlf.common.core.constant.UserStatus;
import com.xlf.common.core.pojo.dto.JwtUserDetails;
import com.xlf.pojo.system.SysUser;
import lombok.Getter;
import lombok.Setter;

import java.util.Set;

@Getter
@Setter
public class UserDetailsImpl extends JwtUserDetails {

    /**
     * 具体的用户实体类
     */
    private SysUser sysUser;

    public UserDetailsImpl(){
        super(null);
    }
    public UserDetailsImpl(SysUser sysUser, Set<String> collectors){
        super(collectors);
        this.sysUser = sysUser;
    }

    @Override
    public String getPassword() {
        return sysUser.getPassword();
    }

    @Override
    public String getUsername() {
        return sysUser.getUserName();
    }

    /**
     * 账号过期
     * @return
     */
    @Override
    public boolean isAccountNonExpired() {
        return !UserStatus.DELETED.getCode().equals(sysUser.getDelFlag());
    }

    /**
     * 锁定异常
     * @return
     */
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    /**
     * 凭证过期
     * @return
     */
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    /**
     * 禁用
     * @return
     */
    @Override
    public boolean isEnabled() {
        return UserStatus.OK.getCode().equals(sysUser.getStatus());
    }

    @Override
    public String toString() {
        super.toString();
        return "UserDetailsImpl{" +
                ", sysUser=" + sysUser +
                '}';
    }

    @Override
    public Object getUserId() {
        return sysUser.getUserId();
    }
}
